package com.xcms.member;

import com.xcms.util.JDBCHelper;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		       //request/获取客户端请求数据的对象
				//response/向客户端发送数据（响应）对象
				//设置响应数据的文档类型
				response.setContentType("text/html");
				//设置响应数据的编码
				response.setCharacterEncoding("utf-8");
				//获取响应的打印流（输出流）
				PrintWriter out = response.getWriter();
				//1、获取客户端数据（参数）
				String name=request.getParameter("name");
				String pwd=request.getParameter("pwd");

				//业务处理
				// 	todo:用户名和密码的判定放在数据库里面判定
				boolean test=JDBCHelper.query1("select * from user where name='"+name+"' and pwd ='"+pwd+"'");
				if(test)
				{
					out.println("<script>alert('恭喜你,登录成功');window.location.href='index2.jsp';</script>");
				}
				else {
					out.println("<script>alert('账户或者用户名错误');window.location.href='login.jsp';</script>");
				}
				out.flush();
				out.close();
	}

	public void
			doPost(HttpServletRequest request, HttpServletResponse response)
					throws ServletException, IOException {

		this.doGet(request, response);
	}

}
